import java.util.Date;
import java.util.Scanner;

/**
 * @author Administrator
 */
public class Homework {
    private static String time;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int time;//所用时间
        System.out.println("欢迎使用小学生口算题卡系统");
        System.out.println("请输入用户名:");
        String username = sc.nextLine();
        System.out.println("请输入密码:");
        int password = sc.nextInt();
        sort(username,password,sc);
    }

    private static void sort(String username, int password, Scanner sc) {
        String name = "lsh";
        int pass = 123456;
        int x=1;
        int y=1;
        int i=1;
        int z;
        int sum1 = 0;
        int sum2 = 0;
        int sum3 = 0;
        int sum4 = 0;
        if (username.equals(name) && password == pass) {
            System.out.println("恭喜你，登陆成功");
            Date date = new Date(System.currentTimeMillis());
            long startMillis = date.getTime();
            while (true) {
                int choice;
                int num;
                System.out.println("1,加法运算");
                System.out.println("2,减法运算");
                System.out.println("3,乘法运算");
                System.out.println("4,除法运算");
                System.out.println("5,退出系统");
                System.out.print("请输入你的选择:");
                choice = sc.nextInt();

                switch (choice) {
                    case 1:
                        System.out.print("请输入你要完成的题目数:");
                        num = sc.nextInt();
                        for ( i = 1; i <= num; i++) {
                            x = (int) (Math.random() * 100);
                            y = (int) (Math.random() * 100);
                            System.out.print(x + "+" + y + "=");
                            z = sc.nextInt();
                            if (z == (x + y)) {
                                System.out.println("恭喜你，回答正确");
                                sum2++;
                            } else {
                                System.out.println("答案错误,正确答案为:" + x + "+" + y + "=" + (x + y));
                            }
                            sum1++;
                        }
                        break;

                    case 2:
                        System.out.print("请输入你要完成的题目数:");
                        num = sc.nextInt();
                        for (i = 1; i <= num; ) {
                            x = (int) (Math.random() * 100);
                            y = (int) (Math.random() * 100);
                            if (x > y) {
                                System.out.print(x + "-" + y + "=");
                                z = sc.nextInt();
                                if (z == (x - y)) {
                                    System.out.println("恭喜你，回答正确");
                                    sum2++;
                                } else {
                                    System.out.println("答案错误,正确答案为:" + x + "-" + y + "=" + (x + y));
                                }
                                sum1++;
                                i++;
                            }
                        }
                        break;

                    case 3:
                        System.out.print("请输入你要完成的题目数:");
                        num = sc.nextInt();
                        for (i = 1; i <= num; i++) {
                            x = (int) (Math.random() * 100);
                            y = (int) (Math.random() * 100);
                            System.out.print(x + "*" + y + "=");
                            z = sc.nextInt();
                            if (z == (x * y)) {
                                System.out.println("恭喜你，回答正确");
                                sum2++;
                            } else {
                                System.out.println("答案错误,正确答案为:" + x + "*" + y + "=" + (x * y));
                            }
                            sum3++;
                        }
                        break;

                    case 4:
                        System.out.print("请输入你要完成的题目数:");
                        num = sc.nextInt();
                        for (i = 1; i <= num; i++) {
                            x = (int) (Math.random() * 100);
                            y = (int) (Math.random() * 100);
                            System.out.print(x + "/" + y + "=");
                            z = sc.nextInt();
                            if (z == (x / y)) {
                                System.out.println("恭喜你，回答正确");
                                sum2++;
                            } else {
                                System.out.println("答案错误,正确答案为:" + x + "/" + y + "=" + (x / y));
                            }
                            sum4++;
                        }
                        break;


                    case 5:
                        System.out.println("总题数：" + sum1 + "答对的题数:" + sum2);
                        Date star = new Date(System.currentTimeMillis());
                        long endMillis = star.getTime();
                        double usertime = (endMillis - startMillis) / 1000;
                        System.out.println("你答题所用时间为：" + usertime + "秒");
                        System.out.println("系统已退出,欢迎下次使用");
                        System.exit(0);
                        break;

                    default:

                        System.out.println("选择错误。请重新选择");
                }
            }
        }
        else
        {
            System.out.println("用户名或密码输入错误");

        }
        i ++;
    }


}
